package com.zwx.bingo.problem;

import com.zwx.bingo.context.ContextHolder;
import org.springframework.context.ApplicationContext;
import org.springframework.util.StringUtils;

import java.net.URI;

public class ProblemType {

    private static ProblemProperties problemProperties;

    public static URI withCode(Object code) {

        ApplicationContext context = ContextHolder.getContext();
        if (null != context) {
            problemProperties = context.getBean(ProblemProperties.class);
        }
        String problemEndpoint = problemProperties.getCodePortalPrefix();
        if (StringUtils.isEmpty(problemEndpoint)) {
            problemEndpoint = "http://code.livingdiy.com/";
        }
        if (!problemEndpoint.endsWith("/")) {
            problemEndpoint += "/";
        }
        return URI.create(problemEndpoint + code);
    }
}
